using System;
using System.Collections.Generic;
using DslCrossModelFramework.ModelRelationship;
using Microsoft.VisualStudio.Modeling;

namespace DslCrossModelFramework.UI {
    /// <summary>
    /// Provides a relative model browser dialog
    /// </summary>
    /// <typeparam name="TRelationshipDefinition">The type of the relationship definition.</typeparam>
    public class ModelElementRelativeTreeTypeEditor<TRelationshipDefinition> : ModelBrowserDialogTypeEditor where TRelationshipDefinition : IModelRelationshipDefinition, new() {

        /// <summary>
        /// Configures the dialog.
        /// </summary>
        /// <param name="dialog">The dialog.</param>
        protected override void ConfigureDialog(ModelElementTreeDialog dialog) {
            base.ConfigureDialog(dialog);
            ModelElement underlyingModelElement = this.TypeDescriptor.ModelElement;
            dialog.RootModelElement = underlyingModelElement;
        }

        /// <summary>
        /// Gets the model relationships.
        /// </summary>
        /// <returns></returns>
        protected override IEnumerable<DslCrossModelFramework.ModelRelationship.IModelRelationshipDefinition> GetModelRelationships(DomainClassInfo parent, string scope) {
            List<IModelRelationshipDefinition> modelRelationships = new List<IModelRelationshipDefinition>();
            foreach (Type melRootType in this.Manager.GetModelDirectory().GetAllModelTypes()) {
                TRelationshipDefinition currentRelDef = new TRelationshipDefinition();
                currentRelDef.ModelRootType = melRootType;
                modelRelationships.Add(currentRelDef);
            }

            return modelRelationships;
        }
    }
}